package dk.itu.KrakMap;

import java.io.*;

public class MainWindow extends javax.swing.JFrame
{
    private KrakMap map;
    private MapController mapC;

    /** Creates new form MainWindow */
    public MainWindow()
    {
        initComponents();
        //String dir = "..\\instance\\Valby\\";
        //String dir = "..\\krakdata\\instance\\Charlottenlund\\";
        //String dir = "..\\instance\\Sjaelland\\";
        String dir = "..\\krakdata\\";
        //String dir = "krakdata\\";
        try
        {
            map = new KrakMap(dir);
            setStatusText("Kortet blev indlæst korrekt");
            mapC = new MapController(map, mapV, this);
        }
        catch (IOException ex)
        {
            setStatusText("<html><font color=red>Der var et problem med at indlæse kortet</font><br/>"
                    + "Tjek om kortdataen ligger på stien: "+dir);
        }
        catch (Exception ex)
        {
            setStatusText("An unexpected error: \""+ex.getMessage()+"\" occured, and couldn't be recovered.");
        }
    }

    public void setStatusText(String text, boolean append)
    {
        if(append)
            statusText.setText(statusText.getText()+". "+text);
        else
            statusText.setText(text);
    }

    public void setStatusText(String text)
    {
        setStatusText(text, false);
    }

    public void setRoadLabel(String text)
    {
        roadNameLabel.setText(text);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        statusText = new javax.swing.JLabel();
        mapV = new dk.itu.KrakMap.MapView();
        roadNameLabel = new javax.swing.JLabel();
        statusText2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        menu_reset = new javax.swing.JMenuItem();
        menu_exit = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setMinimumSize(new java.awt.Dimension(600, 600));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Kf04-kort - Gruppe 11");

        statusText.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        statusText.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        roadNameLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        statusText2.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        jMenu1.setText("File");

        menu_reset.setText("reset");
        menu_reset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_resetActionPerformed(evt);
            }
        });
        jMenu1.add(menu_reset);

        menu_exit.setText("exit");
        menu_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_exitActionPerformed(evt);
            }
        });
        jMenu1.add(menu_exit);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statusText, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(mapV, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
                            .addComponent(roadNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(294, Short.MAX_VALUE))))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addComponent(statusText2, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                    .addGap(313, 313, 313)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusText, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mapV, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(roadNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(68, 68, 68)
                    .addComponent(statusText2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(315, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menu_exitActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_menu_exitActionPerformed
    {//GEN-HEADEREND:event_menu_exitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_menu_exitActionPerformed

    private void menu_resetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_resetActionPerformed
        mapC.resetMap();
    }//GEN-LAST:event_menu_resetActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {

            public void run()
            {
                new MainWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private dk.itu.KrakMap.MapView mapV;
    private javax.swing.JMenuItem menu_exit;
    private javax.swing.JMenuItem menu_reset;
    private javax.swing.JLabel roadNameLabel;
    private javax.swing.JLabel statusText;
    private javax.swing.JLabel statusText2;
    // End of variables declaration//GEN-END:variables
}
